import { InputQuestion, UploadQuestion, QuestionBase, SelectQuestion, TimeQuestion, TextQuestion } from '@/components/public-template';
import { Api } from '@/config/api/archives';
import { Api as ApiSystem } from '@/config/api/system';
import { Api as ApiResource } from '@/config/api/resourceFileInfo';
import { Api as ApiPerson } from '@/config/api/personFile';
import { Api as ApiFile } from '@/config/api/archivesFile';
import dayjs from 'dayjs';
import { regExp } from '@/utils/regExp';
import XEUtils from 'xe-utils';
import { useUserStoreWithOut } from '@/store/modules/user';
const userStore = useUserStoreWithOut();
const loginInfo: any = userStore.getLoginInfo;

class IndexService {
  getQuestions({ source, type }) {
    const questions: QuestionBase<any>[] = [
      new SelectQuestion({
        key: 'source',
        label: '文件来源',
        required: true,
        prompt: '请选择',
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'ARCHIVES_SOURCE'
        }
      }),
      source == 1 ? XEUtils.clone(inNameQuestion) : XEUtils.clone(outNameQuestion),
      new InputQuestion({
        key: 'filesBoxCode',
        label: '档案编码',
        reg: regExp.alphanumer,
        prompt: '输入字符需小于20',
        required: true,
        value: null
      }),
      new InputQuestion({
        key: 'code',
        label: '文件编码',
        reg: regExp.alphanumer,
        prompt: '输入字符需小于20',
        value: null
      }),
      new InputQuestion({
        key: 'fileCode',
        label: '文件号',
        reg: regExp.strLen20,
        prompt: '输入字符需小于20',
        value: ''
      }),
      new SelectQuestion({
        key: 'type',
        label: '载体形式',
        required: true,
        prompt: '请选择',
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'CARRIER_TYPE'
        }
      }),
      new InputQuestion({
        key: 'filePages',
        label: '文件页数',
        type: 'number',
        disabled: type == 4,
        value: null,
        reg: type != 4 ? regExp.positiveInteger : null,
        prompt: '请输入，输入数字需正整数',
        required: type != 4
      }),
      // type == 4 ? XEUtils.clone(entityPages) : XEUtils.clone(otherPages),
      new SelectQuestion({
        key: 'filesType',
        label: '档案类型',
        required: true,
        prompt: '请选择',
        value: null,
        type: 'tree',
        state: {
          url: Api.typefindCanUseTree,
          protType: 'post',
          nameKey: 'name',
          nameValue: 'id',
          nameChildren: 'children'
        }
      }),
      new TextQuestion({
        key: 'filesTypeName',
        hide: true,
        value: null
      }),
      new SelectQuestion({
        key: 'secretLevel',
        label: '保密等级',
        required: true,
        prompt: '请选择',
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'SECRET_LEVEL'
        }
      }),
      new SelectQuestion({
        key: 'eachOther',
        label: '互见号',
        prompt: '请选择',
        value: null,
        state: {
          url: ApiFile.fileGetEachOther,
          protType: 'post',
          nameKey: 'filesBoxCode',
          nameValue: 'filesBoxCode'
        }
      }),
      new SelectQuestion({
        key: 'toDepartment',
        label: '归档部门',
        required: true,
        prompt: '请选择',
        value: loginInfo.orgId,
        type: 'tree',
        state: {
          url: ApiSystem.orgTreeData,
          protType: 'post',
          nameKey: 'name',
          nameValue: 'id',
          nameChildren: 'childOrg'
        }
      }),
      new SelectQuestion({
        key: 'chargeUserId',
        label: '责任者',
        required: true,
        prompt: '请选择',
        value: null,
        state: {
          url: ApiSystem.subjectListSimple,
          protType: 'post',
          nameKey: 'nickName',
          nameValue: 'id',
          showSearch: true,
          optionFilterProp: 'label'
        }
      }),
      new TextQuestion({
        key: 'chargeUserName',
        hide: true,
        value: null
      }),
      new TextQuestion({
        key: 'toDepartmentName',
        hide: true,
        value: loginInfo.orgName
      }),
      new TimeQuestion({
        key: 'fromDate',
        label: '形成日期',
        required: true,
        prompt: '请选择',
        value: dayjs().format('YYYY-MM-DD'),
        state: {
          valueFormat: 'YYYY-MM-DD'
        },
        type: 'alone'
      }),
      new TimeQuestion({
        key: 'toDate',
        label: '归档日期',
        required: true,
        prompt: '请选择',
        value: dayjs().format('YYYY-MM-DD'),
        state: {
          valueFormat: 'YYYY-MM-DD'
        },
        type: 'alone'
      }),
      new SelectQuestion({
        key: 'retentionPeriodDate',
        label: '保管期限',
        required: true,
        prompt: '请选择',
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_LIST_RETENTION_PERIOD_DATE'
        }
      }),
      new InputQuestion({
        key: 'remark',
        label: '说明',
        value: null,
        reg: regExp.len100,
        prompt: '输入字符需小于100',
        state: {
          grid: 12
        }
      }),
      new InputQuestion({
        key: 'attachment',
        label: '附件',
        value: null,
        type: 'slot',
        state: {
          slotName: 'upload',
          grid: 12
        }
      })
      // new UploadQuestion({
      //   key: 'attachment',
      //   label: '附件',
      //   required: true,
      //   prompt: '请上传',
      //   value: null,
      //   controlType: 'upload',
      //   state: {
      //     listType: 'text',
      //     url: ApiResource.resourceUploadFile,
      //     viewUrl: ApiResource.getPreviewFileUrl,
      //     cancelLimit: true,
      //     params: {},
      //     httpOpt: { timeout: 1000 * 60 * 3 },
      //     fieldNames: {
      //       fileId: 'fileId',
      //       name: 'name',
      //       size: 'size',
      //       suffix: 'suffix'
      //     },
      //     previewFile: true
      //   }
      // })
    ];
    return questions;
  }
  getViewQuestions(fileSource) {
    const questions: QuestionBase<any>[] = [
      new TextQuestion({
        key: 'source',
        label: '文件来源',
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'ARCHIVES_SOURCE'
        }
      }),
      new TextQuestion({
        key: 'name',
        label: '文件名称',
        value: null
      }),
      new TextQuestion({
        key: 'filesBoxCode',
        label: '档案编码',
        value: null
      }),
      new TextQuestion({
        key: 'code',
        label: '文件编码',
        value: null
      }),
      new TextQuestion({
        key: 'fileCode',
        label: '文件号',
        value: null
      }),
      new TextQuestion({
        key: 'type',
        label: '载体形式',
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'CARRIER_TYPE'
        }
      }),
      new TextQuestion({
        key: 'filePages',
        label: '文件页数',
        value: null
      }),
      new TextQuestion({
        key: 'filesTypeName',
        label: '档案类型',
        value: null
      }),
      new TextQuestion({
        key: 'secretLevel',
        label: '保密等级',
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'SECRET_LEVEL'
        }
      }),
      new TextQuestion({
        key: 'eachOther',
        label: '互见号',
        value: null
      }),
      new TextQuestion({
        key: 'chargeUserName',
        label: '责任者',
        value: null
      }),
      new TextQuestion({
        key: 'toDepartmentName',
        label: '归档部门',
        value: null
      }),
      new TextQuestion({
        key: 'fromDate',
        label: '形成日期',
        value: null
      }),
      new TextQuestion({
        key: 'toDate',
        label: '归档日期',
        value: null
      }),
      new TextQuestion({
        key: 'retentionPeriodDate',
        label: '保管期限',
        value: null,
        type: 'dictionary',
        state: {
          filterName: 'DMS_ARCHIVES_FILE_LIST_RETENTION_PERIOD_DATE'
        }
      }),
      new TextQuestion({
        key: 'remark',
        label: '说明',
        state: {
          grid: 12
        },
        value: null
      }),
      new UploadQuestion({
        key: 'attachment',
        label: '附件',
        value: null,
        type: 'static',
        state: {
          listType: 'text',
          viewUrl: ApiResource.getPreviewFileUrl,
          params: {},
          previewFile: true,
          fieldNames: {
            fileId: 'fileId',
            name: 'name',
            size: 'size',
            suffix: 'suffix'
          }
        }
      })
    ];
    return questions;
  }
}

// 系统内名称
export const inNameQuestion = new SelectQuestion({
  key: 'name',
  label: '文件名称',
  required: true,
  prompt: '请输入',
  value: null,
  type: 'search',
  state: {
    url: ApiFile.getFileListByFileName,
    protType: 'post',
    nameKey: 'name',
    nameValue: 'name'
  }
});
// 系统外名称
export const outNameQuestion = new InputQuestion({
  key: 'name',
  label: '文件名称',
  required: true,
  reg: regExp.len100,
  prompt: '请输入，字符需小于100',
  value: null
});
// 文件页数-载体类型为实体
export const entityPages = new InputQuestion({
  key: 'filePages',
  label: '文件页数',
  type: 'number',
  disabled: true,
  value: null
});
// 文件页数-载体类型为其他
export const otherPages = new InputQuestion({
  key: 'filePages',
  label: '文件页数',
  required: true,
  type: 'number',
  reg: regExp.positiveInteger,
  prompt: '请输入，输入数字需正整数',
  value: null
});

export default new IndexService();
